<html>
<head>
<body>
<title>MemoryGame</title>
</head>
<style type='text/css'>.output {background-color: #fdffdd;}
body { background-color: #fdffdd; }
#rows {width:150px ; height:50px};
</style>
<h1 style = color:red><center>STEWIE WORLD DOMINATION</center></h1>

<form><center>
<table>
<tr><td id=rawr>Adjustable Table Size (Cannot exceed 36 boxes. YOU CANNOT DEFY MY WILL!):</td>
    <td> Rows <input id=mRow type="text" border="0px" maxlength="2" size="20"></td>
	<td> Columns<input id=mCol type="text" maxlength="2" size="20"></td>
    <td><input id=mBut type="button" value="Submit Values"></td>
</tr>
<div id="tableHolder" border= 1>
</div>
<table> 
<script type='text/javascript'>
	var mRows = 4; var mCols = 4; var arrOfImg;
	var logoUrls = [ 
"http://thespinfactor.com/thetruth/wp-content/uploads/2007/07/statue_of_liberty_800cropped.jpg", "http://www.destination360.com/asia/china/images/s/china-great-wall-of-china.jpg" ,
"http://mitchellexpress.co.uk/images/eiffel-tower.jpg" ,
"http://www.hickerphoto.com/data/media/3/ad_35769n.jpg",
"http://bensguide.gpo.gov/images/symbols/whitehouse_back.jpg", "http://www.pmcluster.com/images/London.gif",
"http://www3.freeze.com/Wallpaper/Water/dw-Niagra-falls-22_m.jpg", "http://travel.nationalgeographic.com/places/images/photos/photo_lg_spain.jpg","http://www.studylanguages.org/images/athens/athens4.jpg", "http://images.businessweek.com/ss/06/07/top_brands/image/yahoo.jpg", "http://www.dorlingkindersley-uk.co.uk/static/html/features/where_to_go/images/12dec/05_sydney.jpg", "http://www.state.gov/cms_images/india_tajmahal_2003_06_252.jpg", "http://geno.com.sapo.pt/coisasblog/2006.03.05.hollywood.sign.sized.jpg", "http://whatscookingamerica.net/Appetizers/AmericanSushi2.JPG", "http://nature.wallpaperme.com/4271-2/Ancient+Mayan+Ruins_+Chichen+Itza_+Mexico.jpg", "http://www.alaska-in-pictures.com/data/media/22/antarctica-icebergs_4608.jpg", "http://www.lasillatours.com/apps/site/files/x21africa.jpg", "http://www.aib.org.au/hk/images/AIB-HongKongBoat.jpg"];

	function getValues(event)
	{
		event.target.disabled=true;
		mRows = document.getElementById('mRow').value; 
		mCols = document.getElementById('mCol').value;
		if (mRows*mCols > 36) { mRows=4; mCols=4; alert("HAHA! VICTORY IS MINE!"); }
		for (var i = 0; i < mRows; i++) { 
			document.getElementById("tableHolder").innerHTML += '<tr id=rawr><br/>';
			for (var j = 0; j < mCols; j++)
				document.getElementById("tableHolder").innerHTML += '<td id=fun> <img> </td>';	
			document.getElementById("tableHolder").innerHTML +='</tr>';
		} 
		arrOfImg = document.getElementsByTagName("img");
		runTheGame(mRows, mCols);
	};
	document.getElementById('mBut').onclick = getValues;
	
function runTheGame(nRows, nCols) {
var counter = 0; var firstMatch = ""; var fMInx = 0;

function reloadBGTable ()
{ 
  var countArr = [];
  for (var y = 0; y<((nRows*nCols)/2); y++)
	countArr.push(0);
for ( var x = 0 ; x<(nRows*nCols); x++) {
  if (x < ((nRows*nCols)/2) && arrOfImg[x].src == arrOfImg[x].explsrc) countArr[x] = countArr[x] + 1;
  if (x >= ((nRows*nCols)/2) && arrOfImg[x].src == arrOfImg[x].explsrc) countArr[x%(nRows*nCols)] = countArr[x%((nRows*nCols)/2)] + 1; }
for ( var z = 0 ; z<(nRows*nCols); z++)
  if (countArr[z%((nRows*nCols)/2)] == 2) arrOfImg[z].src="http://champdesreves.files.wordpress.com/2006/09/stewie-death-ray.gif";
  else { for ( var r = 0 ; r<(nRows*nCols); r++) arrOfImg[r].src=arrOfImg[r].explsrc; alert("INSERT PICTURE HERE"); break; }
}

function necessary() 
{ counter = 0; reloadBGTable(); }

function nothing()
{ var y =0; }

function flipImg(event) 
{
  counter = counter + 1;
  if (counter < 2) { event.target.src = event.target.charsrc; firstMatch = event.target.src; fMInx = event.target.index; }
  else if (counter == 2 && firstMatch == event.target.charsrc && fMInx != event.target.index) { event.target.src = event.target.charsrc; window.setTimeout(nothing, 1000); counter = 0; event.target.src = event.target.explsrc; for ( var z = 0 ; z<(nRows*nCols); z++) if (arrOfImg[z].src == event.target.charsrc) arrOfImg[z].src = event.target.explsrc; }
  else { event.target.src=event.target.charsrc; window.setTimeout(necessary, 1000); counter = 0; }
}

function loadBGTable ()
{ 
for ( var x = 0 ; x<arrOfImg.length; x++)
{
  arrOfImg[x].src ="http://champdesreves.files.wordpress.com/2006/09/stewie-death-ray.gif";
  arrOfImg[x].charsrc =logoUrls[x%((nRows*nCols)/2)];
  arrOfImg[x].explsrc ="http://webtools.gieskes.nl/pages/images/explosion.gif";
  arrOfImg[x].width = "150";
  arrOfImg[x].height = "150";
  arrOfImg[x].onclick = flipImg;
  arrOfImg[x].index = x;
}
}
loadBGTable();
}
</script>
</table>
</table></form></center>

<h5 style = color : blue , size : 16 >  Created by Team Five. Sponsored by the World Destruction Committee. STEWIE: TAKING OVER LIFE</h5>
</body>
</html>